<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>设置我的密码</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <#include "/comm/module-edit.ftl"/>
</head>
<body>
<div class="layui-fluid">
    <div class="layui-row layui-col-space15">
        <div class="layui-col-md12">
            <form class="layui-form" autocomplete="off">
                <div class="layui-card">
                    <div class="layui-card-body">

                        <div class="layui-form">
                            <div class="layui-form-item">
                                <label class="layui-form-label">当前密码</label>
                                <div class="layui-input-inline">
                                    <input type="password" name="oldPwd" id="oldPwd" lay-verify="required"
                                           class="layui-input" lay-reqtext="请输入原密码" lay-affix=“eye”>
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <label class="layui-form-label">新密码</label>
                                <div class="layui-input-inline">
                                    <input type="password" lay-verify="required" id="newPwd" name="newPwd"
                                           class="layui-input" lay-reqtext="请输入新密码" lay-affix=“eye”>
                                </div>
                                <div class="layui-form-mid layui-word-aux">6到16个字符</div>
                            </div>
                            <div class="layui-form-item">
                                <label class="layui-form-label">确认新密码</label>
                                <div class="layui-input-inline">
                                    <input type="password" name="confirmNewPwd" lay-verify="required|rePwd"
                                           lay-affix=“eye”
                                           class="layui-input">
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <div class="layui-input-block">
                                    <button class="layui-btn" lay-submit="" lay-filter="save">确认修改
                                    </button>
                                </div>
                            </div>
                        </div>

                    </div>
                </div>
            </form>
        </div>
    </div>
</div>
<script type="text/javascript" src="${request.contextPath}/assets/js/sha/sha256.js"></script>
<script>
    layui.use("edit", function () {
        let edit = layui.edit;
        var form = layui.form;
        // 自定义校验规则
        form.verify({
            pwd: [/^[\S]{6,12}$/, '密码必须6-12位且不能包含空格'], // 新密码格式校验
            rePwd: function (value) { // 确认密码一致性校验
                var newPwd = $('input[name="newPwd"]').val();
                if (newPwd !== value) return '两次输入的密码不一致';
            }
        });
        edit.render(function (obj) {
            console.log(obj)
            obj["oldPwd"] = sha256_digest(obj["oldPwd"])
            obj["newPwd"] = sha256_digest(obj["newPwd"])
            console.log(obj)
            post("${(request.contextPath)!}/platform/user/pwd/save", obj, function () {
                layer.msg("修改成功", {icon: 1});
                setTimeout(function () {
                    closeTab()
                }, 2000)

            });
        })

    });
</script>
</body>
</html>